﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T.FAS.Runtime.DataAccess.Common
{
    /// <summary>
    /// 读取字典类
    /// </summary>
    public sealed class CommonUtil
    {
        /// <summary>
        /// 在字典中取值
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dict"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T GetValue<T>(Dictionary<string, object> dict, string key)
        {
            if (!dict.ContainsKey(key))
                return default;
            if (dict.TryGetValue(key, out object value))
            {
                try
                {
                    return (T)value;
                }
                catch (Exception)
                {
                }
            }
            return default;
        }
    }
}
